<?php

namespace common\service;


use common\model\TaskModel;
use support\SingletonTrait;

class FilterService
{
    use SingletonTrait;

    protected $producerRoleCodes = [
        TaskService::STEP_PRODUCER_CODE,
        TaskService::EXECUTIVE_PRODUCER_CODE,
        TaskService::BUSINESS_PRODUCER_CODE,
        TaskService::PRODUCER_CODE,
    ];

    /**
     *  任务库快速筛选条件
     * @return array
     */
    public function taskQuickSearch()
    {

        $data = teamones_request('teamones-im', 'user/get_my_user_info', [])['data'];
        $stepCategoryIdList = [];
        if (!empty($data['role_info'])) {
            if (array_intersect($this->producerRoleCodes, array_column($data['role_info'], 'code'))) {
                foreach ($data['department_info'] ?? [] as $departmentInfo) {
                    if (!empty($departmentInfo['step_category_ids'])) {
                        $tempStepCategoryIdList = explode(',', $departmentInfo['step_category_ids']);
                        $stepCategoryIdList = $stepCategoryIdList + $tempStepCategoryIdList;
                    }
                }
            }
        }



        // 制片分配
        $res['producer_assign'] = [
            'assign_status' => [TaskModel::ASSIGN_STATUS_DEFAULT],
            'step_category_id' => [],
        ];
        // 我的制作任务
        $res['my_execute_task'] = [
            'is_me_executor' => true,
            'task_status' => ['not_started', 'ready_to_start', 'inprogress', 'submitted',
                'feedback', 'ready_to_publish', 'wait_for_party_a_review', 'wait_assemble',
                'wait_partyb_submit', 'remake',
            ],
        ];
        // 我的审核任务
        $res['my_review_task'] = [
            'is_me_review' => true,
        ];

        if (!empty($stepCategoryIdList)) {
            $res['producer_assign']['step_category_id'] = array_map('intval', array_unique(array_filter($stepCategoryIdList)));
        }
        return $res;
    }
}
